Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jul 20, 2025

This PR implements an integrated web preview feature with element selection capabilities for AI context, similar to Windsurf IDE.

Features

  • 🌐 Web Preview Panel: Preview web applications directly within VSCode
  • 🎯 Element Selection: Click on UI elements to select them and extract their context
  • 📱 Responsive Design: Switch between different device viewports (mobile, tablet, desktop)
  • 🔍 Context Extraction: Automatically extract HTML, CSS, position, and metadata from selected elements
  • 🤖 AI Integration: Selected element context is automatically sent to the AI assistant
  • 🛡️ Security: Handles cross-origin restrictions gracefully with appropriate error messages

Implementation Details

  • Created WebPreviewProvider class to manage the preview panel
  • Added element selection overlay with DOM inspection capabilities
  • Implemented comprehensive element context extraction (HTML, CSS, position, selectors, etc.)
  • Integrated with the existing chat system to send element context to AI
  • Added responsive controls with device presets
  • Created comprehensive tests for the new functionality
  • Added documentation with usage guide

Testing

  • All tests pass ✅
  • TypeScript compilation successful ✅
  • ESLint checks pass ✅

Screenshots

The web preview panel includes:

  • URL input bar
  • Device selector dropdown
  • Element inspector toggle button
  • Responsive iframe for web content

Usage

  1. Open the Web Preview panel from the Roo Code sidebar
  2. Enter a URL and click Go
  3. Click the 🎯 button to enable element selection
  4. Click on any element to send its context to the AI

Closes #5971


Important

Adds integrated web preview panel with element selection and AI context extraction in VSCode, including new commands, tests, and documentation.

  • Behavior:
    • Adds WebPreviewProvider class in WebPreviewProvider.ts for integrated web preview and element selection.
    • Supports responsive design testing and element context extraction (HTML, CSS, position, metadata).
    • Integrates with AI assistant to send selected element context.
    • Handles cross-origin restrictions with error messages.
  • Commands:
    • Adds openWebPreview command in registerCommands.ts to focus on the web preview panel.
  • Testing:
    • Adds tests in WebPreviewProvider.spec.ts for web preview functionality.
  • Documentation:
    • Adds web-preview.md for usage guide and feature details.
  • Misc:
    • Updates package.json to include new web preview view and command.
    • Updates ESLint config to disable no-undef for preview.js.

This description was created by Ellipsis for a9e4f1e. You can customize this summary. It will automatically update as commits are pushed.

- Implement WebPreviewProvider for managing preview panel
- Add element selection overlay with DOM inspection
- Extract comprehensive element context (HTML, CSS, position, etc.)
- Integrate selected element context with AI chat
- Add responsive controls and device simulation
- Support multiple device viewports (mobile, tablet, desktop)
- Handle cross-origin restrictions gracefully
- Add comprehensive tests for WebPreviewProvider
- Update documentation with usage guide

Closes #5971
@roomote roomote bot requested review from cte, jr and mrubens as code owners July 20, 2025 05:38
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. documentation Improvements or additions to documentation enhancement New feature or request labels Jul 20, 2025
}

export class WebPreviewProvider implements vscode.WebviewViewProvider {
public static readonly viewId = "roo-code.webPreview"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The viewId is set to 'roo-code.webPreview' but in package.json (and in registerCommands) the id is 'roo-cline.WebPreviewProvider'. These should be consistent to ensure the webview is correctly registered.

Suggested change
public static readonly viewId = "roo-code.webPreview"
public static readonly viewId = "roo-cline.WebPreviewProvider"

- Validate and sanitize URLs before loading in iframe
- Use URL constructor to parse and validate URLs
- Only allow HTTP and HTTPS protocols
- Use setAttribute instead of direct property assignment
- Add proper error handling for invalid URLs

This fixes:
- Client-side URL redirect vulnerability
- DOM text reinterpreted as HTML
- Client-side cross-site scripting (XSS)
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 20, 2025
roomote bot pushed a commit that referenced this pull request Jul 20, 2025
- Changed viewId from "roo-code.webPreview" to "roo-cline.WebPreviewProvider" to match package.json and registerCommands.ts
- This fixes the issue identified by ellipsis-dev bot in PR #5981
- Security vulnerabilities were already fixed in the original PR
@SannidhyaSah
Copy link
Collaborator

@daniel-lxs I don't think this pr solves the issue . I'm working on this issue myself . Feel free to close it .

@daniel-lxs daniel-lxs closed this Jul 22, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 22, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Add integrated web application preview with element selection for AI context

5 participants